package br.com.android.games.daedal;

import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.TranslateAnimation;

public class ChangeAnimation implements AnimationListener {
	private View viewer;

	public ChangeAnimation(View v) {
		viewer = v;
	}

	public static Animation inFromRightAnimation(View mContainer) {
		/*
		 * Animation inFromRight = new TranslateAnimation(
		 * Animation.RELATIVE_TO_PARENT, +1.0f, Animation.RELATIVE_TO_PARENT,
		 * 0.0f, Animation.RELATIVE_TO_PARENT, 0.0f,
		 * Animation.RELATIVE_TO_PARENT, 0.0f); inFromRight.setDuration(350);
		 * inFromRight.setInterpolator(new AccelerateInterpolator()); return
		 * inFromRight;
		 */
		// Find the center of the container
		final float centerX = mContainer.getWidth() / 2.0f;
		final float centerY = mContainer.getHeight() / 2.0f;

		// Create a new 3D rotation with the supplied parameter
		// The animation listener is used to trigger the next animation
		Rotate3dAnimation rotation = new Rotate3dAnimation(180, 0, centerX,
				centerY, 1000.0f, false);
		rotation.setDuration(1000);
		rotation.setFillAfter(true);
		rotation.setInterpolator(new AccelerateInterpolator());

		// rotation.setAnimationListener(new DisplayNextView(position));
		mContainer.startAnimation(rotation);
		
		//mContainer.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

		return rotation;
	}

	public static Animation outToLeftAnimation(View mContainer) {
		/*
		 * Animation outtoLeft = new TranslateAnimation(
		 * Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT,
		 * -1.0f, Animation.RELATIVE_TO_PARENT, 0.0f,
		 * Animation.RELATIVE_TO_PARENT, 0.0f); outtoLeft.setDuration(350);
		 * outtoLeft.setInterpolator(new AccelerateInterpolator()); return
		 * outtoLeft;
		 */
		// Find the center of the container
		final float centerX = mContainer.getWidth() / 2.0f;
		final float centerY = mContainer.getHeight() / 2.0f;

		// Create a new 3D rotation with the supplied parameter
		// The animation listener is used to trigger the next animation
		Rotate3dAnimation rotation = new Rotate3dAnimation(0, 180, centerX,
				centerY, 1000.0f, true);
		rotation.setDuration(1000);
		rotation.setFillAfter(true);
		rotation.setInterpolator(new AccelerateInterpolator());
	//	mContainer.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
	//	rotation.setAnimationListener(new ChangeAnimation(mContainer));
		mContainer.startAnimation(rotation);

		return rotation;
	}

	// for the next movement
	public static Animation inFromLeftAnimation() {
		Animation inFromLeft = new TranslateAnimation(
				Animation.RELATIVE_TO_PARENT, -1.0f,
				Animation.RELATIVE_TO_PARENT, 0.0f,
				Animation.RELATIVE_TO_PARENT, 0.0f,
				Animation.RELATIVE_TO_PARENT, 0.0f);
		inFromLeft.setDuration(350);
		inFromLeft.setInterpolator(new AccelerateInterpolator());
		return inFromLeft;
	}

	public static Animation outToRightAnimation() {
		Animation outtoRight = new TranslateAnimation(
				Animation.RELATIVE_TO_PARENT, 0.0f,
				Animation.RELATIVE_TO_PARENT, +1.0f,
				Animation.RELATIVE_TO_PARENT, 0.0f,
				Animation.RELATIVE_TO_PARENT, 0.0f);
		outtoRight.setDuration(350);
		outtoRight.setInterpolator(new AccelerateInterpolator());
		return outtoRight;
	}

	@Override
	public void onAnimationEnd(Animation animation) {
		inFromRightAnimation(viewer);		
	}

	@Override
	public void onAnimationRepeat(Animation animation) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onAnimationStart(Animation animation) {
		// TODO Auto-generated method stub
		
	}
}
